package net.tngou.crawler.company;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class TypeUtil {

	public static void main(String[] args) throws IOException {
		String html=FileUtils.readFileToString(new File("C:\\Users\\Administrator\\git\\tgcrawler\\tgcrawler\\config\\html.txt"));
		Document doc = Jsoup.parse(html);
		Element element = doc.getElementsByClass("dropdown-menu").get(4);
		Elements lis = element.getElementsByClass("industry");
		JSONArray array=new JSONArray();
		lis.forEach(e->{
			String industry = e.attr("data-industry");
			if(!"0".equals(industry)) {
				JSONObject jsonObject= new JSONObject();
				jsonObject.put("id", industry);
				jsonObject.put("name", e.text());
				JSONArray list=new JSONArray();
				Elements es = element.getElementsByAttributeValue("data-industry", industry);
				es.forEach(m->{
					String value = m.attr("data-value");
					if(!"0".equals(value)&&!"".equals(value)) {
						JSONObject json= new JSONObject();
						json.put("id", value);
						json.put("name", m.text());
						list.add(json);
					}
				});
				jsonObject.put("list", list);
				array.add(jsonObject);
			}
		});
		System.err.println(array);
	}
}
